/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.zumbits.avd.logger;

import br.com.zumbits.avd.Config;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *
 * @author zumbits
 */
public class Log {

    public static final String FILE;
    public static final String PATH;

    static {
        List<String>list = Config.getPathLog();
        FILE = list.get(0);
        PATH = list.get(1);
    }
    //
    private static boolean line = false;

    public Log() {
    }

    public static void print(String user, String log) {
        try {
            String path = PATH + File.separator + user + File.separator + FILE;
            File fileLog = new File(path);
            fileLog.createNewFile();

            PrintWriter printWriter = new PrintWriter(new FileWriter(fileLog, true), true);
            String body =
                    "<div style='width: 50%; text-align: center;' id='tbLine' class='" + ((line) ? "color" : "ncolor") + "'>" +
                    "<div style='float: left;'>" + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date()) + "</div>" +
                    "<div style='float: center;'>" + log +
                    "<div style='float: right;'>" + user + "</div></div>" +
                    "</div>";

            printWriter.println(body);

            line = !line;

            printWriter.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
